<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房屋编号" prop="houseId">
        <el-input
          v-model="queryParams.houseId"
          placeholder="请输入房屋编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="papersCode">
        <el-input
          v-model="queryParams.papersCode"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="认证状态" prop="informationSts">
        <el-select v-model="queryParams.informationSts" placeholder="请选择认证状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.HOUSE018"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          :disabled="pass"
          @click="handlePass"
          size="mini"
        >审批通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          :disabled="refuse"
          @click="handleRefuse"
          size="mini"
        >审批拒绝</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房屋编号" align="center" prop="houseId" />
      <el-table-column label="身份证" align="center" prop="papersCode" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="电话号" align="center" prop="tel" />
      <el-table-column label="正面身份证名称" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.frontidCardHttp)">{{ scope.row.frontidCardName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="反面身份证名称" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.versoidCardHttp,scope.row.versoidCardName)">{{ scope.row.versoidCardName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房产证名称" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.homeCardHttp,scope.row.homeCardName)">{{ scope.row.homeCardName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="认证状态" align="center" prop="informationSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.HOUSE018" :value="scope.row.informationSts"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <el-dialog :title="titleCard" :visible.sync="showCard" width="500px" append-to-body>
     <div style="text-align:center">
     <img style="width:400px" :src="cardUrl" />
     </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="showCard=false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { housePass, houseRefuse, listInformation} from "@/api/house/information";

export default {
  name: "Information",
  dicts: ['HOUSE018'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      pass: true,
      refuse: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 身份认证表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseId: null,
        papersCode: null,
        userName: null,
        frontidCardName: null,
        versoidCardName: null,
        homeCardName: null,
        createDate: null,
        informationSts: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      cardUrl:'',
      titleCard:'',
      showCard:false
    };
  },
  created() {
    this.getList();
  },
  methods: {
  openCard(id,name){
    this.titleCard = name
    this.cardUrl=id;
    this.showCard=true;
  },
    /** 查询身份认证列表 */
    getList() {
      this.loading = true;
      listInformation(this.queryParams).then(response => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        houseId: null,
        papersCode: null,
        userName: null,
        tel: null,
        openid: null,
        frontidCardHttp: null,
        frontidCardName: null,
        frontidCard: null,
        versoidCardHttp: null,
        versoidCardName: null,
        versoidCard: null,
        homeCardHttp: null,
        homeCardName: null,
        homeCard: null,
        createDate: null,
        informationSts: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.pass = !selection.length;
      this.refuse = !selection.length;
      selection.map(item => {
        if(item.informationSts!=0){
          this.pass = true;
          this.refuse = true;
        }
      })
      this.ids = selection.map(item => item.id)
    },
    handlePass() {
       housePass(this.ids).then(response => {
           this.$modal.msgSuccess("执行成功");
           this.getList();
       });
     },
     handleRefuse() {
       houseRefuse(this.ids).then(response => {
           this.$modal.msgSuccess("执行成功");
           this.getList();
       });
     },
    /** 导出按钮操作 */
    handleExport() {
      this.download('house/information/export', {
        ...this.queryParams
      }, `information_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
